<!DOCTYPE  HTML>
<html>
	<head>
		
		<script type="text/javascript" src="../resources/script.js"></script>
		<meta charset="utf-8">
  		<meta name="viewport" content="width=device-width, initial-scale=1">
  		<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
  		<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  		<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
  		<script type="text/javascript" src="../resources/bootstrap-datepicker.js"></script>
		<link rel="stylesheet" href="../resources/datepicker.css"></link >
  		<link rel="stylesheet" href="../resources/style.css" />
  		<style type="text/css">
  			
  		</style>
	</head>
	<body>
<script>
$(document).ready(function(){
  $("#btnaddTrainee").click(function(){
    $("#divTraineeinfo").hide();
  });
});

$(document).ready(function(){
  $("#btnaddNewUser").click(function(){
    $("#divTraineeinfo").show();
  });
});
$(function(){
			$(".datepicker").datepicker({format: 'yyyy-mm-dd'});
});
</script>
		 <?php
                        foreach (glob("../model/*.php") as $filename)
                        {
                                include_once $filename;
                        }

                        foreach (glob("../dao/*.php") as $filename)
                        {
                                include_once $filename;
                        }

			if($_SERVER['REQUEST_METHOD'] == 'POST')
			{
				$name = $_POST['name'];
				$address = $_POST['address'];
				$dob = $_POST['dob'];
				$doj = $_POST['doj'];
				$college = $_POST['college'];
				$email_id = $_POST['email_id'];
				$password = $_POST['password'];
				$role = $_POST['role'];

				$profiledao = new ProfileDAOImpl();
				$userdao    = new UserDAOImpl();
				$user_list  = $userdao->listUsers()->getArrayList();

				if(array_key_exists('emp_id',$_POST))
                                {
                                        $emp_id = $_POST['emp_id'];
					$user   = new User($email_id, $password, $role, null, $emp_id);
				}
				else
				{
					$user = new User($email_id, $password, $role);
				}
				
				$userdao->saveOrUpdate($user);
				$profile = new Profile($user->getId(), $user->getEmpId(), $name, $address, $dob, $doj, $college);

				$profiledao->saveOrUpdate($profile);
			}
		?>

		<div id="ahmainpnl" >
			<img id="ahlogo" src="../resources/logo.png"></img>
			<div id="ahheaderpnl">
				<p id="hSess">Trainees / Interns</p>
				<button id="btnaddTrainee" type="button" class="btn btn-primary" data-toggle="collapse" data-target="#addnewT" class="adbtn" >Add Trainee</button>
			      
			</div>
			<div id="ahmenupnl">
				<a href="home_admin.php" id="ahbtnhome" class="btn btn-success">Home</a>
				<!--button type="button" id="ahbtnhome" class="btn btn-success" onclick="window.open('home_admin.html')">Home</button-->
				<hr/>
				<a href="addUser.php" id="ahbtnhome" class="btn btn-info">Users</a>
				<!--button type="button" id="ahbtnuser" class="btn btn-info" onclick="window.open('addUser.html')">Users</button-->
				<a href="addTechnology.php" id="ahbtnhome" class="btn btn-info">Technologies</a>
				<!--button type="button" id="ahbtntech" class="btn btn-info" onclick="window.open('addTechnology.html')">Technologies</button-->
				<a id="ahbtnlogout" href="../login.html">Logout</a>
			</div>
			<div id="ahcontentpnl">
				
				
				
				<div id="addnewT" class="collapse container">
				 	<form role="form" action='' method='POST'>
  						<table class="tbladd">
  							
  							<tr>
  								<td><input type="text" class="form-control" name="emp_id" id="emp_id" placeholder="Emp-Id" required></td>
  								<td><input type="text" class="form-control" name="name" id="name" placeholder="First Name.Last Name" required></td>	
  							</tr>
  							<tr>
  								<td><input type="text" class="form-control" name="address" id="address" placeholder="Address" required></td>
  							
  								<td><input type="text" class="form-control" name="college" id="college" placeholder="College" required></td>
  							</tr>
							<tr>
                                   <td><input type="email" class="form-control" name="email_id" id="txtemail" placeholder="Email" required></td>

                                   <td><input type="text" class="form-control" name="password" id="password" placeholder="Password" required></td>
                            </tr>
  							<tr>
  								<td><input type="text" class="datepicker" name = "dob" id="dob" placeholder="Date Of Birth" title="Date of Birth" style="width: 40%;" required></td>
  								<td><input type="text" class="datepicker" name = "doj" id="doj" placeholder="Date Of Joining" title="Date of Joining" style="width: 40%;" required></td>
  							</tr>
							<tr>
								 <td><input type="text" class="form-control" name = "role" id="role" placeholder="Role" title="Role" style="width: 40%;" required></td>

							</tr>
							<tr>
  							<td>
  							<button  id="btnaddNewUser" type="submit" class="btn btn-default" class"adbtn">Add</button>
							</td>
							</tr>
							</table>
					</form>
					</div>

				<div id="divTraineeinfo" class="container">
					<table class="table table-hover">
					        <thead>
          						<tr>
            							<th>ID</th>
            							<th>Emp-ID</th>
								<th>Name</th>
								<th>DOB</th>
								<th>Joining Date</th>
								<th>College</th>
	
          						</tr>
        					</thead>
        					<tbody>
							<?php
								$profiledao = new ProfileDAOImpl();
								$profile_list = $profiledao->listProfiles()->getArrayList();

								if(isset($profile_list))
								{
									foreach($profile_list as $profile)
									{
							?>	
        						<tr>
								<td><?php print $profile->getId(); ?></td>
								<td><?php print $profile->getEmpId(); ?></td>
            							<td>
								<?php
									$name=$profile->getName(); 
									print $name;
								?>
								</td>
								<td><?php print $profile->getDateOfBirth(); ?></td>
								<td><?php print $profile->getDateOfJoining(); ?></td>
								<td><?php print $profile->getCollege(); ?></td>
							</tr>  	
							<?php
									}
								}
								else
								{
									echo"!!!NO User Profile";
								}
							?>
  	      					</tbody>
      					</table>
				</div>
			</div>
			<div class="divfooter" >
					<p>© 2007-2015 Spring Computing Technologies Pvt. Ltd., All Rights Reserved.</p>
			</div>
		
			</body>
	
</html>
